package com.example.psychologicalappointmentsystem.Controller;

import com.example.psychologicalappointmentsystem.Entity.User;
import com.example.psychologicalappointmentsystem.Enum.QualificationStatus;
import com.example.psychologicalappointmentsystem.Enum.UserRole;
import com.example.psychologicalappointmentsystem.JpaRepository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin")
public class AdminController {

    @Autowired
    private UserRepository userRepository;

    // 管理员审核咨询师
    @PutMapping("/approve-consultant/{userId}")
    public ResponseEntity<?> approveConsultant(@PathVariable Long userId) {
        // 查找用户
        User user = userRepository.findById(userId).orElse(null);
        if (user == null || user.getRole() != UserRole.CONSULTANT) {
            return ResponseEntity.badRequest().body("此用户不为咨询师");
        }
        // 审核通过，修改状态
        user.setStatus(QualificationStatus.APPROVED);
        userRepository.save(user);

        return ResponseEntity.ok("审核通过");
    }
    @PutMapping("/reject-consultant/{userId}")
    public ResponseEntity<?> rejectConsultant(@PathVariable Long userId) {
        // 查找用户
        User user = userRepository.findById(userId).orElse(null);
        if (user == null || user.getRole() != UserRole.CONSULTANT) {
            return ResponseEntity.badRequest().body("此用户不为咨询师");
        }
        // 审核通过，修改状态
        user.setStatus(QualificationStatus.REJECTED);
        userRepository.save(user);

        return ResponseEntity.ok("审核不通过！");
    }
}

